# Maintainer: kpcyrd <git@rxv.cc>

pkgname=diesel-cli
pkgver=2.0.3
pkgrel=1
pkgdesc="CLI for the Diesel crate"
arch=('loong64' 'x86_64')
url="https://diesel.rs/"
license=('MIT' 'Apache')
replaces=('diesel_cli')
depends=('sqlite' 'postgresql-libs' 'libmariadbclient')
makedepends=('cargo')
source=(https://github.com/diesel-rs/diesel/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz
        Cargo.lock)
sha512sums=('f311071daee4209081c595123afea202c99795f82322baf9b2a551b5fbecb4bfb885f51243e68d16a2da4515369ba583aa95815114c14559295fb1add71f9ec6'
            '0f585d592b299da9a49ff639d802d0f5051a25363e6c97c4dd7788c38fedf0eda1e9d04d89b23c9118cc850a8d9458203f1a4d40b079f2e547414c333f473243')
b2sums=('2d00042af4172ebae386fc3f92cd00c60f31ce7b45279b5292850167fc518d7747c2ee0ceac1f12102b96e06c313a88bd5785718e66ec6d5225b5985a13c2dce'
        '4957231bc6de458fa2baf292cd47e211b4200a0688cdce131ea93c44256a3d50eb2a2f3fb7ddd94dd01df3c298a5d549cc51384705114295b7eee50c7172a591')

prepare() {
  cp Cargo.lock "diesel-${pkgver}"
  cd "diesel-${pkgver}/diesel_cli"
  cargo fetch --locked --target "$CARCH-unknown-linux-gnu"
}

updlockfiles() {
  cd "diesel-${pkgver}"
  rm -f Cargo.lock
  cargo update
  cp Cargo.lock "${outdir}/"
}

build() {
  cd "diesel-${pkgver}/diesel_cli"
  RUSTFLAGS="--cap-lints allow" cargo build --frozen --release
}

check() {
  cd "diesel-${pkgver}/diesel_cli"
  # tests require a debug build to be present
  RUSTFLAGS="--cap-lints allow" cargo test --no-default-features --features sqlite
}

package() {
  cd "diesel-${pkgver}"
  install -Dm755 "target/release/diesel" "${pkgdir}/usr/bin/diesel"

  install -d "${pkgdir}/usr/share/bash-completion/completions" \
             "${pkgdir}/usr/share/zsh/site-functions" \
             "${pkgdir}/usr/share/fish/vendor_completions.d"
  "${pkgdir}/usr/bin/diesel" completions bash > "${pkgdir}/usr/share/bash-completion/completions/diesel"
  "${pkgdir}/usr/bin/diesel" completions zsh > "${pkgdir}/usr/share/zsh/site-functions/_diesel"
  "${pkgdir}/usr/bin/diesel" completions fish > "${pkgdir}/usr/share/fish/vendor_completions.d/diesel.fish"

  install -Dm644 LICENSE-MIT -t "${pkgdir}/usr/share/licenses/${pkgname}"
}

# vim:set ts=2 sw=2 et:
